package com.tentative.competition.web.controller.schedule.service;

import com.tentative.competition.common.core.controller.BaseController;
import com.tentative.competition.common.core.domain.AjaxResult;
import com.tentative.competition.common.core.result.ApiResult;
import com.tentative.competition.common.core.result.PageResult;
import com.tentative.competition.common.model.schedule.param.ScheduleOrgInfoAddParam;
import com.tentative.competition.common.model.schedule.resp.ScheduleOrgInfoResp;
import com.tentative.competition.schedule.service.ScheduleOrgInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @auther: Smile Huang
 * @date: 2023/6/24 20:37
 * @desc:
 * @version: 2.0
 */
@Api(tags = "service-赞助商（组织）管理")
@RestController
@RequestMapping("/service/orgInfo")
public class ScheduleOrgInfoController extends BaseController {

    @Autowired
    private ScheduleOrgInfoService orgInfoService;

    @ApiOperation("查询组织列表-分页")
    @GetMapping("/list")
    public ApiResult list(ScheduleOrgInfoAddParam param) {
        PageResult<ScheduleOrgInfoResp> list = orgInfoService.pageList(param);
        return ApiResult.ofPage(list.getContent(),list.getTotal());
    }

    /**
     * 获取组织明细
     * @param id
     * @return
     */
    @ApiOperation("获取组织明细")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(orgInfoService.getInfo(id));
    }


    /**
     * 创建｜修改组织信息
     * @param param
     * @return
     */
    @ApiOperation("创建｜修改组织信息")
    @PostMapping("/add-edit")
    public AjaxResult addOrEdit(@RequestBody ScheduleOrgInfoAddParam param) {
        orgInfoService.addOrEdit(param);
        return AjaxResult.success();
    }

    @ApiOperation("删除组织信息")
    //@PreAuthorize("@ss.hasPermi('pc:flow:remove')")
    @PostMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<Long> ids) {
        return toAjax(orgInfoService.deleteOrgInfo(ids));
    }

}
